package com.lilihub.miaosha.common;

import lombok.Data;

import java.util.Spliterator;

/**
 * @BelongsProject: miaosha
 * @BelongsPackage: com.lilihub.miaosha.common
 * @Author: LiYing
 * @CreateTime: 2021-04-22 10:36
 * @Description:
 */
@Data
public class Result<T> {


    private int code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(T data) {

        this.code = 0;
        this.msg = "success";
        this.data = data;
    }

    public Result(CodeMsg codeMsg) {

        if (codeMsg == null) return;

        this.code = codeMsg.getCode();
        this.msg = codeMsg.getMsg();
    }

    //成功时调用
    public static <T> Result<T> success(T data){
        return new Result<T>(data);
    }


    //失败时调用
    public static <T> Result<T> error(CodeMsg codeMsg){
        return new Result<T>(codeMsg);
    }



}
